# -*-makefile-*-
#
# by exa aka Eray Ozkural 2001
# see COPYING file that comes with this distribution

# Recursive make support

# Exported variables
export INCLUDES
export CXX
export PATH
export top_srcdir

##ifndef $(NO_EXTENDED_RECURSION)

# Each target depends on its subdirectories' targets
# according to the following schema
#x:	x-recursive x-local do-x
dir-deprule = $(call eval,$(1): $(addsuffix -$(1),$(SUBDIRS)) \
$(1)-local do-$(1)-info do-$(1))
$(call map,dir-deprule,$(targets))
define do-x-info

	@echo;echo "** Making $(1) in current directory"
endef
do-x-inforule = $(call eval,do-$(1)-info: $(do-x-info))
$(call map,do-x-inforule,$(targets))

# Make targets of a dir
# Takes into account directory interdependencies
define make-dir-targets

	@echo;echo "** Recursively making $(1) in $(2)";\
	@-(cd $(2) && $(MAKE) $(1))
endef
dir-target = $(call eval,$(2)-$(1): $($(2)_DEPS)-$(1) $(make-dir-targets) )
x-target = $(call map2,dir-target,$(targets),$(1))

#$(call x-target,assoc-gen)

# Each dir defines a set of targets using x-target

dir-x = $(call x-target,$(1))
$(call map,dir-x,$(SUBDIRS))


.PHONY:	CURRENT $(SUBDIRS) 

##endif

ifneq ($(NO_EXTENDED_RECURSION),)

$(x-recursive):
	@set fnord $(MAKEFLAGS); amf=$$2; \
	dot_seen=no; \
	target=`echo $@ | sed s/-recursive//`; \
	list='$(SUBDIRS)'; for subdir in $$list; do \
	  echo "** Making $$target in $$subdir"; \
	  if test "$$subdir" = "."; then \
	    dot_seen=yes; \
	    local_target="$$target-jm"; \
	  else \
	    local_target="$$target"; \
	  fi; \
	  (cd $$subdir && $(MAKE) $(jm-makeflags) $$local_target) \
	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
	done; \

#	if test "$$dot_seen" = "no"; then \
#	  $(MAKE) $(JM_MAKEFLAGS) "$$target-jm" || exit 1; \
#	fi; test -z "$$fail"


# Flags to pass down to all sub-makes.
jm-makeflags = \
	"AR_FLAGS=$(AR_FLAGS)" \
	"AR_FOR_TARGET=$(AR_FOR_TARGET)" \
	"AS_FOR_TARGET=$(AS_FOR_TARGET)" \
	"BISON=$(BISON)" \
	"CC_FOR_BUILD=$(CC_FOR_BUILD)" \
	"CC_FOR_TARGET=$(CC_FOR_TARGET)" \
	"CFLAGS=$(CFLAGS)" \
	"CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
	"CHILLFLAGS=$(CHILLFLAGS)" \
	"CHILL_FOR_TARGET=$(CHILL_FOR_TARGET)" \
	"CHILL_LIB=$(CHILL_LIB)" \
	"CXX_FOR_BUILD=$(CXX_FOR_BUILD)" \
	"CXXFLAGS=$(CXXFLAGS)" \
	"CXXFLAGS_FOR_TARGET=$(CXXFLAGS_FOR_TARGET)" \
	"CXX_FOR_TARGET=$(CXX_FOR_TARGET)" \
	"DESTDIR=$(DESTDIR)" \
	"DLLTOOL_FOR_TARGET=$(DLLTOOL_FOR_TARGET)" \
	"INSTALL=$(INSTALL)" \
	"INSTALL_DATA=$(INSTALL_DATA)" \
	"INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
	"INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
	"LDFLAGS=$(LDFLAGS)" \
	"LEX=$(LEX)" \
	"LD_FOR_TARGET=$(LD_FOR_TARGET)" \
	"LIBCFLAGS=$(LIBCFLAGS)" \
	"LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
	"LIBCXXFLAGS=$(LIBCXXFLAGS)" \
	"LIBCXXFLAGS_FOR_TARGET=$(LIBCXXFLAGS_FOR_TARGET)" \
	"M4=$(M4)" \
	"MAKE=$(MAKE)" \
	"MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
	"NM_FOR_TARGET=$(NM_FOR_TARGET)" \
	"RANLIB_FOR_TARGET=$(RANLIB_FOR_TARGET)" \
	"RPATH_ENVVAR=$(RPATH_ENVVAR)" \
	"SHELL=$(SHELL)" \
	"EXPECT=$(EXPECT)" \
	"RUNTEST=$(RUNTEST)" \
	"RUNTESTFLAGS=$(RUNTESTFLAGS)" \
	"TARGET_SUBDIR=$(TARGET_SUBDIR)" \
	"WINDRES_FOR_TARGET=$(WINDRES_FOR_TARGET)" \
	"YACC=$(YACC)" \
	"bindir=$(bindir)" \
	"datadir=$(datadir)" \
	"exec_prefix=$(exec_prefix)" \
	"includedir=$(includedir)" \
	"infodir=$(infodir)" \
	"libdir=$(libdir)" \
	"libexecdir=$(libexecdir)" \
	"lispdir=$(lispdir)" \
	"libstdcxx_incdir=$(libstdcxx_incdir)" \
	"libsubdir=$(libsubdir)" \
	"localstatedir=$(localstatedir)" \
	"mandir=$(mandir)" \
	"oldincludedir=$(oldincludedir)" \
	"prefix=$(prefix)" \
	"sbindir=$(sbindir)" \
	"sharedstatedir=$(sharedstatedir)" \
	"sysconfdir=$(sysconfdir)"\
	"top_srcdir=$(top_srcdir)" 
endif

